package com.gla.giliair.web.admin;

import com.gla.giliair.entity.Discount;
import com.gla.giliair.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/25 20:39
 */
@Api(tags = "折扣方案管理模块")
@RestController
@RequestMapping("/api/adminX")
public class AdminDiscountController extends BaseController {
    @ApiOperation(value = "获取航空公司所属折扣方案列表", notes = "获取航空公司所属折扣方案列表", produces = "application/json")
    @GetMapping("/findDiscount")
    @ResponseBody
    public Map<String, Object> findDiscount(//默认按id正向排序
                                            @RequestParam("companyId") Long companyId,
                                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "pageSize", defaultValue = "16") Integer pageSize) {
        return discountService.findDiscountsByCompanyId(companyId, page, pageSize);
    }

    @ApiOperation(value = "添加折扣方案", notes = "添加折扣方案", produces = "application/json")
    @PostMapping("/addDiscount")
    @ResponseBody
    public Map<String, Object> addDiscount(@RequestParam("companyId") Long companyId,
                                           @RequestParam(value = "adultDiscount", required = false) BigDecimal adultDiscount,
                                           @RequestParam(value = "childrenDiscount", defaultValue = "0.5") BigDecimal childrenDiscount,
                                           @RequestParam(value = "normalDiscount", required = false) BigDecimal normalDiscount,
                                           @RequestParam(value = "silverDiscount", required = false) BigDecimal silverDiscount,
                                           @RequestParam(value = "goldDiscount", required = false) BigDecimal goldDiscount) {
        Discount discount = new Discount();
        discount.setCompanyId(companyId);
        discount.setAdultDiscount(adultDiscount);
        discount.setChildrenDiscount(childrenDiscount);
        discount.setNormalDiscount(normalDiscount);
        discount.setSilverDiscount(silverDiscount);
        discount.setGoldDiscount(goldDiscount);

        return discountService.addDiscount(discount);
    }

    @ApiOperation(value = "删除折扣方案", notes = "删除折扣方案", produces = "application/json")
    @PostMapping("/deleteDiscount")
    @ResponseBody
    public Map<String, Object> deleteDiscount(@RequestParam("discountId") Long discountId) {
        return discountService.deleteDiscount(discountId);
    }

}
